package com.zhou.system.management.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.zhou.common.lib.model.Response;
import com.zhou.system.management.entity.SysPost;
import com.zhou.system.management.model.ao.SysDeptAddAo;
import com.zhou.system.management.model.ao.SysPostUpdateAo;
import com.zhou.system.management.service.impl.SysPostServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 岗位信息表 前端控制器
 * </p>
 *
 * @author zxf
 * @since 2023-05-18
 */
@Api(tags = "岗位模块")
@ApiSupport(order = 1)
@RestController
@RequestMapping("/sys-post")
public class SysPostController {

    @Autowired
    private SysPostServiceImpl postService;

    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "查询岗位")
    @PostMapping("/query")
    public Response<List<SysPost>> query() {
        LambdaQueryWrapper<SysPost> queryWrapper = Wrappers.<SysPost>lambdaQuery()
                .orderByAsc(SysPost::getPostId);
        List<SysPost> list = postService.list(queryWrapper);
        return Response.success(list);
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "新增岗位")
    @PostMapping("/add")
    public Response add(@RequestBody SysDeptAddAo addAo) {
        postService.add(addAo);
        return Response.success();
    }

    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "更新岗位")
    @PostMapping("/update")
    public Response update(@RequestBody SysPostUpdateAo updateVo) {
        postService.update(updateVo);
        return Response.success();
    }

    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "删除岗位")
    @DeleteMapping("/{postId}")
    public Response delete(@PathVariable Long postId) {
        //todo 部门下面有子部门，或部门下面有用户，则不能删除
        postService.removeById(postId);
        return Response.success();
    }
}
